<?php

namespace app\api\controller;

use app\common\controller\Api;
use app\admin\model\Premises;
use function PHPSTORM_META\type;

/**
 * 楼盘接口
 */
class Building extends Api
{
    protected $noNeedLogin = ['*'];
    protected $noNeedRight = ['*'];

    /**
     * 楼盘
     *
     */
    public function index()
    {
        $buildId=input('id/d');
        $buildType=input('type/d',1);//1=推荐,2=在售,3=将开
        $this->success('获取成功', [
            'build' => $this->build($buildId,$buildType),     //获取楼盘信息
        ], 1);
    }

    /**
     * 楼盘
     *
     */
    public function build($buildId,$buildType)
    {
        $model = new Premises();
        if (empty($buildId)) {
            $list = $model->where(['status' => 1,'type'=>$buildType])
                ->field('id,name,image,square,scene,address')
                ->limit(0, 4)
                ->select();
            foreach ($list as &$v) {
                $v['image'] = strtolower(config("url_domain_root") . str_replace('\\', '/', $v['image']));
            }
            return $list;
        } else {
            $detail = $model->where(['status' => 1, 'id' => $buildId])
                ->field('id,name,image,square,scene,address')
                ->find();
            return $detail;
        }

    }
}
